<?php
ob_start();
include 'common/header.html';
include 'common/left.html';
include("common/page.php");
include_once 'module/common/Db.class.php';
$out_html=ob_get_contents();
ob_end_clean();
use \PFT\Db;
$conf =include 'module/common/db.conf.php';
Db::Conf($conf['remote_1']);
$Db = Db::Connect();
$page_ids = substr($page_ids,0,-1);
$pageSize=$_REQUEST['pageSize']?$_REQUEST["pageSize"]:10;
$currentPage=$_REQUEST["currentPage"]?$_REQUEST["currentPage"]:1;
$offset=($currentPage-1)*$pageSize;
$sel_share_page = "SELECT id,title,short_url,hash from pft_marketing_sp where fid in(?) order by id desc limit $offset,$pageSize";
$stmt = $Db->prepare($sel_share_page);
$stmt->execute(array($_SESSION['sid']));
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
if (!count($rows))
    exit('没有营销活动的相关分享页面');
foreach($rows as $k => $v){
    $rows[$k]['qr_url'] = 'http://s.12301.cc/pft/resource/codes/'.$v['hash'].'.png';
}
$sel_count = "SELECT count(*) from pft_marketing_sp where fid in(?)";
$stmt = $Db->prepare($sel_count);
$stmt->execute(array($_SESSION['sid']));
$count = $stmt->fetchAll(PDO::FETCH_ASSOC);
$count = $count[0]['count(*)'];

if($_REQUEST['act']=="download"){//下载图片   
    $code_img = 'http://qr.liantu.com/api.php?text='.$_REQUEST['txt'];
	$file=file_get_contents($code_img);
	header('Content-type: image/jpg'); 
	$name="分享活动二维码";
	header("Content-Disposition:attachment;filename=$name.jpg");
	echo $file;
	exit;
}
echo $out_html;
//http://s.12301.cc/pft/resource/codes/rx.png  取二维码的地址 rx换成sp的hash
?>
<!--<script type="text/javascript" src="http://www.12301.cc/js/plugin/json2.js"></script>-->
<!--[if lt IE 7]><div id="childListWrap" class="lt-ie10 lt-ie9 lt-ie8 lt-ie7 ie6 childListWrap"> <![endif]-->
<!--[if IE 7]><div id="childListWrap" class="lt-ie10 lt-ie9 lt-ie8 ie7 childListWrap"> <![endif]-->
<!--[if IE 8]><div id="childListWrap" class="lt-ie10 lt-ie9 ie8 childListWrap"> <![endif]-->
<!--[if IE 9]><div id="childListWrap" class="lt-ie10 ie9 childListWrap"><![endif]-->
<!--[if gt IE 9]><!--><div id="childListWrap" class="childListWrap"> <!--<![endif]-->
<link rel="stylesheet" href="http://www.12301.cc/css/common/www.12301.cc.global.css"/>
<link rel="stylesheet" href="http://www.12301.cc/css/marketing_list.css"/>
<link rel="stylesheet" href="css/page.css" media="all" />
<h3 class="mc_title"><span class="mctit_1"><span class="mctit_2">分享页面列表</span></span></h3></br>
	<input type="hidden" id="lid" value="<?=$_REQUEST['lid']?>" /> 
	<input type="hidden" name="sort" value='<?=json_encode($sort)?>'/>
	<a id="addChildBtn_a" class="addChildBtn" href="marketing_csp.html" target="_blank">创建</a>
<table id="listTable" class="proTable fixed">
		<thead id="proTableHead">
			<tr>
				<th class="col_1">分享名称</th>
				<th class="col_2">关联活动</th>
				<th class="col_3">二维码</th>
				<th class="col_4">操作</th>
			</tr>
		</thead>
		<tbody>
            <?foreach($rows as $v){?>
			<!-- <tr class="marTop"><td colspan="4" style="border:0px"></td></tr> -->
            <tr class="listBody borderBottom" data-id="<?=$v['id']?>">
				<td class="col_1 col" rowspan="1">
					<span><?=$v['title']?></span>
				</td>
				<td class="col_2 col about_img_g" >
					<span class="about_img" data-id="<?=$v['id']?>"><img src="http://www.12301.cc/images/dian_show.png"  ></span>
					
				</td>
				<td class="col_3 col" rowspan="1">
				<!-- onclick="window.location.href='?act=download&txt=<?=$v['short_url']?>'" -->
					<span class="daoma"><img src="<?=$v['qr_url']?>" ><a href="?act=download&txt=<?=$v['short_url']?>">下载二维码</a></span>
					<span class="bigpic none"><img class="normal" src="<?=$v['qr_url']?>" onerror="javascript:this.src='http://www.12301.cc/images/sorry_pic.png'"/></span>
				</td>
				<td class="col_4 col" rowspan="1">
					<!-- <a class="do edit" href="markteing_show.html?lid=<?=$_REQUEST['lid']?>&type=b&id=<?=$ct['id']?>" target="_blank"><i class="cpicon edit"></i><i class="cpicon edit-hover hover"></i></a> -->
					<a class="do close" href="###"><i class="cpicon close"></i><i class="cpicon close-hover hover"></i></a>
				</td>
            </tr>
			<!-- <tr class="marbuttom"><td colspan="4" style="border:0px"></td></tr> -->
            <?}?>
			
		</tbody>
	</table>
	<ul id="suggest_ul"></ul>
	<?if(count($rows)!=0){page($count,$currentPage,$pageSize);}?>
<script type="text/javascript" src="http://www.12301.cc/js/global/www.12301.cc.global.js"></script>
<script type="text/javascript" src="http://www.12301.cc/js/marketing/marketing_list.js"></script>
<script type="text/javascript" src="js/ui/PopWindow.js"></script>
</div>
<script>
	
	
	$("#listTable").on("mouseover",".listBody .about_img",function(e){
		var target = $(e.currentTarget);
		var id = target.attr("data-id");
		var leftq = $(this).offset().left;
		var left_1 = $(".col_1").width();
		var left_2 = $(".col_2").width();
		var left_3 =(leftq/20);
		var left = left_1+left_3;
		//alert(lefta);
		//var righta =(rightq/2);
		$("#suggest_ul").css({"display":"block","left":left,"top":$(this).offset().top-180})
		  $.ajax({		
					"url" : "http://www.12301.cc/call/jh_marketing.php",
					"data" : {action:'activity_name',m_id:id},
					"dataType":"json",
					"type": 'POST', 
					"success":function(data){
						$("#suggest_ul").show(0);
						var contents="";
						for(var i in data) {
							var keywords = data[i].activity_name;
							contents=contents+"<li>"+keywords+"</li>";
							}
							$("#suggest_ul").html(contents); 
							
						}          
				});
		})
		
	$("#listTable").on("mouseout",".listBody .about_img",function(e){
		var target = $(e.currentTarget);
		var id = target.attr("data-id");
		$("#suggest_ul").css({"display":"none"});
	})
		
	//创建营销活动
	$("#addChildBtn").on("click",function(e){
			var lid = $("#lid").val();
			window.location.href = "http://www.12301.cc/markteing_show.html?lid="+lid;
			return false;
		})
	$("#listTable").on("click",".listBody .close",function(e){ //删除
			var target = $(e.currentTarget);
			var result = window.confirm("确定要删除此景点吗");
			if(!result) return false;
			var citem = target.parents(".listBody");
			deleteChild(citem.data("id"),citem);
		})

	function deleteChild(id,citem){ 
		//if(!id) return false;
		PFT_GLOBAL.G.Ajax({
			url : "http://www.12301.cc/call/jh_marketing.php",
			type : "POST",
			dataType : "JSON",
			data : {
				action : "sp_delete",
				id : id,
				
			},
			loading : function(){
			},
			removeLoading : function(){
			}
		},function(code){
			if(code == '200'){
				citem.remove();
				restor();
				PFT_GLOBAL.U.Alert("success",'<p style="width:160px">删除成功</p>',1.5 * 1000);
			}else{
				PFT_GLOBAL.U.Alert("fail",'<p style="width:160px">删除失败，请稍后重试</p>',1.5 * 1000);
			}
		})
	}
	
	
	var t;
		
	
	$("#listTable").on("mouseover",".listBody .daoma",function(e){
			var target = $(e.currentTarget);
			var imgDiv=$(target).next();
			t=setTimeout(function(){
				imgDiv.removeClass("none");
				imgDiv.children().first().animate({width:"350px"});},"500");
		})
	$("#listTable").on("mouseout",".listBody .daoma",function(e){
			var target = $(e.currentTarget);
			var imgDiv=$(target).next();
			clearTimeout(t);
			imgDiv.addClass("none");
			$(this).parent().next().children().first().width(0);
		});
</script>
<?php include('common/footer.html')?>